#ifndef _VECTOR_HPP_
#define _VECTOR_HPP_

#include <cmath>

#include "definitions.hpp"

namespace ALGEBRA
{
    class Matrix;

    class Vector
    {
        friend class Matrix;
    private:
        real_t  *_v;
        int Size;
        bool _created;

        Vector( )
        {
            _created = false;
            _v = NULL;
        }
    public:
        // конструкторы деструкторы
        Vector( int i)
        {
            _created = false;
            Size = i;
            Create( Size);
        }
        ~Vector ( )
        {
            Delete( );
        }
        void Create( int N)
        {
            Delete( );

            Size = N;
            _v = new real_t[ Size];
            _created = true;
        }
        void Create( real_t * V, int I)
        {
            Delete( );
            Create ( I);
            for ( int i = 0; i < Size; i++)
            {
                _v[ i] = V[ i];
            }
        }
        void Delete( )
        {
            if ( _created)
            {
                std::cout << std::endl << _v << std::endl;
                delete [] _v;
                _v = NULL;
                _created = false;
            }
        }
        ////////////////////////////////////////////////////////////
        /// Текущее значение координат вектора                   ///
        real_t *v()
        {
            return _v;
        }

        real_t operator[] ( int I)
        {
            return _v[ I];
        }

        /// Сложение|вычитание
        Vector operator+= ( Vector const &  vec)
        {
            for ( int i = 0; i < Size; i++)
            {
                _v[ i] += vec._v[ i];
            }
            return *this;
        }

        Vector operator+  ( Vector const & vec)
        {
            Vector result( vec);

            for ( int i = 0; i < Size; i++)
            {
                result._v[ i] += _v[ i];
            }
            return result;
        }

        Vector operator-= ( Vector const &  vec)
        {
            for ( int i = 0; i < Size; i++)
            {
                _v[ i] -= vec._v[ i];
            }
            return *this;
        }


        Vector operator-  ( Vector const &  vec)
        {
            Vector result( vec);

            for ( int i = 0; i < Size; i++)
            {
                result._v[ i] -= _v[ i];
            }
            return result;
        }

        Vector operator-  ( )
        {
            Vector result;

            for ( int i = 0; i < Size; i++)
            {
                result._v[ i] = -_v[ i];
            }
            return result;
        }

        Vector operator+  ( )
        {
            return *this;
        }

       ///  Произведение вектора на число
        Vector operator*= ( const real_t N)
        {
            for ( int i = 0; i < Size; i++)
            {
                _v[ i] *= N;
            }
            return *this;
        }
        Vector operator*  ( const real_t N)
        {
            Vector vec ( *this);

            for ( int i = 0; i < Size; i++)
            {
                vec._v[ i] *= N;
            }
            return vec;
        }
        /// Скалярное произведение
        real_t operator* ( const Vector & vec)
        {
            real_t result = 0.0;
            for ( int i = 0; i < Size; i++)
            {
                result += _v[ i] * vec._v[ i];
            }
            return result;
        }
    }; //class Vector
} //namespace ALGEBRA
#endif //_VECTOR_HPP_
